package com.cat.binaryTree;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/check-subtree-lcci/?envType=problem-list-v2&envId=xhsq2On3
 * @create 2025/10/2 20:48
 * @since JDK17
 */

public class Solution100 {
    boolean dfs(TreeNode r1, TreeNode r2) {
        if (r2 == null) {
            return true;
        }
        if (r1 == null || r1.val != r2.val) {
            return false;
        }
        return dfs(r1.left, r2.left) && dfs(r1.right, r2.right);
    }

    public boolean checkSubTree(TreeNode t1, TreeNode t2) {
        if (t1 == null) {
            return false;
        }
        return dfs(t1, t2) || checkSubTree(t1.left, t2) || checkSubTree(t2.right, t2);
    }
}
